package com.hq.fxh.No1_Infromation.Video.Activity;

import android.content.Intent;
import android.graphics.Bitmap;
import android.media.MediaMetadataRetriever;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.hq.fxh.No0_ChengQu.Activity.BaseActivity;
import com.hq.fxh.R;
import com.hq.fxh.Utils.LogUtils;
import com.hq.fxh.imageLoader.video.VideoItem;
import com.hq.fxh.imageLoader.video.VideoPicker;

import java.util.ArrayList;


public class VideoUpdateActivity extends BaseActivity implements View.OnClickListener {


    protected TextView tvUpdataVideoUpLoad;
    protected TextView tvUpdataVideoCancel;
    protected ImageView imageUpdataVideoIcon;
    protected EditText editUpdataVideoTitle;
    protected EditText editUpdataVideoContent;

    protected String videoPath;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_video_update;
    }

    @Override
    protected void initView() {
        tvUpdataVideoUpLoad = (TextView) findViewById(R.id.tv_UpdataVideo_UpLoad);
        tvUpdataVideoUpLoad.setOnClickListener(VideoUpdateActivity.this);
        tvUpdataVideoCancel = (TextView) findViewById(R.id.tv_UpdataVideo_Cancel);
        tvUpdataVideoCancel.setOnClickListener(VideoUpdateActivity.this);
        imageUpdataVideoIcon = (ImageView) findViewById(R.id.image_UpdataVideo_Icon);
        editUpdataVideoTitle = (EditText) findViewById(R.id.edit_UpdataVideo_title);
        editUpdataVideoContent = (EditText) findViewById(R.id.edit_UpdataVideo_Content);
    }

    @Override
    protected void initData() {
        Bitmap bitmap;
        try {
            VideoPicker videoPicker = VideoPicker.getInstance();
            ArrayList<VideoItem> selectedVideos = videoPicker.getSelectedVideos();
            if (selectedVideos == null || selectedVideos.size() == 0) {
                Intent intent = getIntent();
                Bundle extras = intent.getExtras();
                videoPath = extras.getString("path");
            } else {
                VideoItem videoItem = selectedVideos.get(0);
                videoPath = videoItem.path;
            }

 /*           if (videoPath == null || videoPath.equals("null")) {

                LogUtils.startToash(this, "收到的视频！" + videoPath);
            }*/
        } catch (Exception e) {
        } finally {
            if (videoPath == null) {
                LogUtils.startToash(this, "视频选择失败！");
            }
            LogUtils.e(videoPath + "收到的视频地址");
            MediaMetadataRetriever media = new MediaMetadataRetriever();
            media.setDataSource(videoPath);
            bitmap = media.getFrameAtTime();
            imageUpdataVideoIcon.setImageBitmap(bitmap);
        }

    }

    @Override
    public void onClick(View view) {
        if (view.getId() == R.id.tv_UpdataVideo_UpLoad) {
            LogUtils.startToash(this, "上传视频开始");
        } else if (view.getId() == R.id.tv_UpdataVideo_Cancel) {
            finish();
        }
    }
}
